/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import utils.HashGenerator;

/**
 *
 * @author Stefan Martinov <stefan.martinov@gmail.com>
 *
 *
 */
@Entity
public class RegisteredUser extends AbstractEntity implements Serializable {

    private static final long serialVersionUID = 1L;
    @Basic(optional = false)
    @Column(name = "first_name", nullable = false)
    protected String firstName;
    @Basic(optional = false)
    @Column(name = "last_name", nullable = false)
    protected String lastName;
    @Basic(optional = false)
    @Column(name = "email", nullable = false)
    protected String email;
    @Basic(optional = false)
    // Hash od sifre radi dodatne sigurnosti
    @Column(name = "password_hash", nullable = false)
    protected String password_hash;
    @Basic(optional = false)
    @Column(name = "verified", nullable = false)
    protected boolean verified;
    // Kod koji se generise i salje klijentu kako bi verifikacija prosla
    @Basic(optional = false)
    @Column(name = "verification_code", nullable = false,unique=true)
    protected String verificationCode;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "registeredUser", fetch = FetchType.LAZY)
    protected List<Event> events;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "registeredUser", fetch = FetchType.EAGER)
    protected List<Contact> contacts;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "registeredUser", fetch = FetchType.LAZY)
    protected List<EventComment> comments;

    public RegisteredUser(){};

    public RegisteredUser(String firstName,String lastName,String email,String pass){
        verified = false;
        verificationCode = String.valueOf(System.currentTimeMillis())+String.valueOf( HashGenerator.generateHash(email));
        this.password_hash = pass;//HashGenerator.generateHash(pass);
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
    }

    public List<Contact> getContacts() {
        return contacts;
    }

    public void setContacts(List<Contact> contacts) {
        this.contacts = contacts;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public List<Event> getEvents() {
        return events;
    }

    public void setEvents(List<Event> events) {
        this.events = events;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getPassword_hash() {
        return password_hash;
    }

    public void setPassword_hash(String password_hash) {
        this.password_hash = password_hash;
    }

    public String getVerificationCode() {
        return verificationCode;
    }

    public void setVerificationCode(String verificationCode) {
        this.verificationCode = verificationCode;
    }

    public boolean isVerified() {
        return verified;
    }

    public void setVerified(boolean verified) {
        this.verified = verified;
    }

    public List<EventComment> getComments() {
        return comments;
    }

    public void setComments(List<EventComment> comments) {
        this.comments = comments;
    }

    

}
